package com.linkai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkai.dto.admin.business.saleReback.ProductShowDto;
import com.linkai.entity.SaleRebackOrderProduct;
import com.linkai.entity.Storage;
import com.linkai.mapper.*;
import com.linkai.service.SaleRebackOrderProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yamon
 * @since 2021-03-19
 */
@Service
public class SaleRebackOrderProductServiceImpl extends ServiceImpl<SaleRebackOrderProductMapper, SaleRebackOrderProduct> implements SaleRebackOrderProductService {
    @Autowired
    private SaleorderProductMapper saleorderProductMapper;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private MoneyaccountMapper moneyaccountMapper;
    @Autowired
    private StorageMapper storageMapper;
    /**
     * 获得所有已经出售的商品
     *
     * @return list
     */
    @Override
    public List<ProductShowDto> getAllSaledProducts() {
        List<Integer> storageIds = saleorderProductMapper.getDistinctStorageId();
        //查出所有的出售商品
        final List<ProductShowDto> productShowDtos = storageIds.stream().map(storageId -> {
            final ProductShowDto productShowDto = new ProductShowDto();
            final Storage storage = storageMapper.selectById(storageId);
            productShowDto.setId(storage.getProId());
            productShowDto.setStorageId(storage.getId());
            productShowDto.setProPrice(storage.getProPrice());
            productShowDto.setProNum(storage.getProNum());
            //库存信息
            productShowDto.setStorageNum(storage.getProNum());
            productShowDto.setProTitle(storage.getProTitle());
            productShowDto.setProUnit(storage.getProUnit());
            return productShowDto;
        }).collect(Collectors.toList());
        return productShowDtos;
    }

}
